package com.dinadi.yidi.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.dinadi.yidi.R;
import com.dinadi.yidi.bean.CartItemListBean;
import com.dinadi.yidi.bean.MessageBean;
import com.dinadi.yidi.http.HttpListener;
import com.dinadi.yidi.http.UpdateView;
import com.dinadi.yidi.http.interfaces.CommonInterface;
import com.dinadi.yidi.ui.activity.DesignerHmePageActivity;
import com.dinadi.yidi.ui.activity.ProductDetailsActivity;
import com.dinadi.yidi.ui.view.SmoothCheckBox;
import com.dinadi.yidi.utils.ImageUtils;
import com.dinadi.yidi.utils.JsonUtil;
import com.dinadi.yidi.utils.SharePreferencesHelper;
import com.dinadi.yidi.utils.ToastUtil;

import java.math.BigDecimal;

/**
 * author: JiaYu.He
 * Date: 2017/11/6
 * Time: 11:48
 */
public class MyShoppingCartsAdapter extends BaseExpandableListAdapter {

    private Context mContext;
    private CartItemListBean goodBean;
    private UpdateView updateViewListener;
    private String tag;
    private int groupId, childId, childSize, groupPosition, allCount;
    private String[] split;
    private BigDecimal allMoney;
    private String cartItemIds;
    private int type;//0减   1、加


    public void addDate(CartItemListBean goodBean) {
        this.goodBean = goodBean;
        notifyDataSetChanged();
    }

    public MyShoppingCartsAdapter(Context context) {
        this.mContext = context;

    }

    //获取组元素数目 
    @Override
    public int getGroupCount() {
        return goodBean.getCartItemList().size();
    }

    //获取子元素数目 
    @Override
    public int getChildrenCount(int groupPosition) {
        return goodBean.getCartItemList().get(groupPosition).getCartItemList().size();
    }

    //获取组元素对象 
    @Override
    public Object getGroup(int groupPosition) {
        return goodBean.getCartItemList().get(groupPosition);
    }

    //获取子元素对象 
    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition);
    }

    //获取组元素Id
    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    //获取子元素Id 
    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }


    /*主要是用来判断ExpandableListView内容id是否有效的(返回true or false)，
    系统会跟据id来确定当前显示哪条内容，也就是firstVisibleChild的位置。*/
    @Override
    public boolean hasStableIds() {
        return false;
    }

    //加载并显示组元素 
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        GroupViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_shopingcart_group, parent, false);
            holder = new GroupViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (GroupViewHolder) convertView.getTag();
        }
        holder.cbGroupItem.setTag(groupPosition);
        holder.group_item_layout.setTag(groupPosition);
//        holder.clear_invalid.setTag(groupPosition);
//        holder.clear_invalid.setOnClickListener(listener);
        holder.cbGroupItem.setOnClickListener(listener);
        holder.group_item_layout.setOnClickListener(listener);
        holder.clear_invalid.setOnClickListener(new clearOnClickListener(groupPosition));
        holder.tvPosition.setText(goodBean.getCartItemList().get(groupPosition).getUserName());
        if (goodBean.getCartItemList().get(groupPosition).getUserName().equals("失效商品")) {
            holder.cbGroupItem.setVisibility(View.GONE);
            holder.clear_invalid.setVisibility(View.VISIBLE);
        } else {
            holder.cbGroupItem.setVisibility(View.VISIBLE);
            holder.clear_invalid.setVisibility(View.GONE);
        }
        //根据获取的状态设置是否被选中
        if (goodBean.getCartItemList().get(groupPosition).isSelected()) {
            if (!holder.cbGroupItem.isChecked()) {
                holder.cbGroupItem.setChecked(true);
            }
        } else {
            holder.cbGroupItem.setChecked(false);
        }
        return convertView;
    }


    ///加载子元素并显示  
    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ChildViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_shopingcart_child, parent, false);
            holder = new ChildViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ChildViewHolder) convertView.getTag();
        }
        String tag = groupPosition + "," + childPosition;
        holder.cbItem.setTag(tag);
        holder.tvReduce.setTag(tag);
        holder.tvAdd.setTag(tag);
        holder.imgIcon.setTag(tag);
        holder.item_layout.setTag(tag);
        holder.cbItem.setOnClickListener(listener);
        holder.tvReduce.setOnClickListener(listener);
        holder.tvAdd.setOnClickListener(listener);
        holder.item_layout.setOnClickListener(listener);
        //根据获取的状态设置是否被选中
        if (goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).isSelected()) {
            holder.cbItem.setChecked(true);
        } else {
            holder.cbItem.setChecked(false);
        }
        //设置数据
        String price = goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).getUnitPrice();
        String originalPrice = goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).getOriginalPrice();
        holder.tvPrice.setText("￥" + price);
        if (!price.equals(originalPrice)) {
            holder.original_price.setText("￥" + originalPrice);
            holder.original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        }else {
            holder.original_price.setText("");
        }

        holder.tv_good_choose.setText("已选：" + goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).getNameValue());
        holder.tvGoodName.setText(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).getProductTitle());
        /*2-售罄 3-失效*/
        String status = goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).getStatus();
        if (status.equals("2")) {
            holder.layout_change_num.setVisibility(View.GONE);
            holder.cbItem.setVisibility(View.GONE);
            holder.img_product_state.setVisibility(View.VISIBLE);
            holder.img_product_state.setImageResource(R.drawable.img_product_state);
            holder.tvGoodName.setTextColor(ContextCompat.getColor(mContext, R.color.color_666666));
            holder.tv_good_choose.setTextColor(ContextCompat.getColor(mContext, R.color.color_999999));
            holder.tvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.color_999999));
        } else if (status.equals("3")) {
            holder.layout_change_num.setVisibility(View.GONE);
            holder.cbItem.setVisibility(View.GONE);
            holder.img_product_state.setVisibility(View.VISIBLE);
            holder.img_product_state.setImageResource(R.drawable.img_product_state_sx);
            holder.tvGoodName.setTextColor(ContextCompat.getColor(mContext, R.color.color_666666));
            holder.tv_good_choose.setTextColor(ContextCompat.getColor(mContext, R.color.color_999999));
            holder.tvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.color_999999));
        } else {
            holder.layout_change_num.setVisibility(View.VISIBLE);
            holder.cbItem.setVisibility(View.VISIBLE);
            holder.img_product_state.setVisibility(View.GONE);
            holder.tvGoodName.setTextColor(ContextCompat.getColor(mContext, R.color.color_333333));
            holder.tv_good_choose.setTextColor(ContextCompat.getColor(mContext, R.color.color_666666));
//            holder.tvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.color_F91D48));
        }
        String imgUrl = goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).getCoverImg();
        ImageUtils.loadImageView(mContext, imgUrl, holder.imgIcon);

        //对商品数量的监听
//        EditTextWatcher textWatcher = (EditTextWatcher) holder.etCount.getTag(KEY_DATA);
//        if (textWatcher != null) {
//            holder.etCount.removeTextChangedListener(textWatcher);
//        }
        holder.etCount.setText(String.valueOf(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).getQuantity()));
        //  EditTextWatcher watcher = new EditTextWatcher(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition));
        //   holder.etCount.setTag(KEY_DATA, watcher);
        //    holder.etCount.addTextChangedListener(watcher);

        holder.etCount.setText(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(childPosition).getQuantity());

        return convertView;

    }

   /* */

    /**
     * 商品数量EditText内容改变的监听
     *//*
    class EditTextWatcher implements TextWatcher {

        private CartItemListBean.ContentBean.GoodDetailBean GoodDetail;

        public EditTextWatcher(CartItemListBean.ContentBean.GoodDetailBean item) {
            this.GoodDetail = item;
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (!TextUtils.isEmpty(s.toString().trim())) {
                String textNum = s.toString().trim();
                GoodDetail.setQuantity(textNum);

            }
        }
    }*/

    /*用来判断某Group某个child是否可可选。
    我们可以添加条件控制某Group某个child可点或不可点击。
    当不加任何条件直接返回false,所有的组的child均不可点击。*/
    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SmoothCheckBox checkBox;
            tag = v.getTag().toString();

            groupId = 0;
            childId = 0;
            childSize = 0;
            groupPosition = 0;
            allCount = goodBean.getAllCount();//被选中的item数量
            allMoney = goodBean.getAllMoney();
            if (allMoney == null) {
                allMoney = new BigDecimal(0);
            }
            if (tag.contains(",")) {
                split = tag.split(",");
                groupId = Integer.parseInt(split[0]);
                childId = Integer.parseInt(split[1]);
            } else {
                groupPosition = Integer.parseInt(tag);
                childSize = goodBean.getCartItemList().get(groupPosition).getCartItemList().size();
            }
            cartItemIds = goodBean.getCartItemIds();
            if (cartItemIds == null) {
                cartItemIds = "";
            }
            switch (v.getId()) {
                case R.id.cb_group_item:
                    checkBox = (SmoothCheckBox) v;
                    //根据父checkbox的选中状态设置存储数据里面商品是否被选中
                    goodBean.getCartItemList().get(groupPosition).setSelected(!checkBox.isChecked());
                    //如果没有选择的话  全选
                    if (!checkBox.isChecked()) {
                        /*循环所有子元素*/
                        for (int i = 0; i < childSize; i++) {
                            /*如果子元素的某一个没被选择*/
                            if (!goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).isSelected()) {
                                /*被选中的item数量加一*/
                                allCount++;
                                /*设置为被选中*/
                                goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).setSelected(!checkBox.isChecked());
//                                allMoney += Integer.valueOf(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getQuantity())
//                                        * Double.parseDouble(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getUnitPrice());

                                allMoney = allMoney.add(new BigDecimal(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getQuantity()).multiply(new BigDecimal(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getUnitPrice())));
                                cartItemIds += goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getId() + ",";
                            }
                        }
                    } else {
                        /*取消选择*/
                        allCount -= childSize;
                        for (int i = 0; i < childSize; i++) {
                            goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).setSelected(!checkBox.isChecked());
//                            allMoney -= Integer.valueOf(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getQuantity())
//                                    * Double.parseDouble(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getUnitPrice());
                            allMoney = allMoney.subtract(new BigDecimal(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getQuantity()).multiply(new BigDecimal(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getUnitPrice())));
                            cartItemIds = cartItemIds.replaceAll(goodBean.getCartItemList().get(groupPosition).getCartItemList().get(i).getId() + ",", "");

                        }

                    }
                    //父item选中的数量
                    int fCount = 0;
                    //判断是否所有的父item都被选中，决定全选按钮状态
                    for (int i = 0; i < goodBean.getCartItemList().size(); i++) {
                        if (goodBean.getCartItemList().get(i).isSelected()) {
                            fCount++;
                        }
                    }
                    if (fCount == goodBean.getCartItemList().size()) {
                        goodBean.setAllSelect(true);
                    } else {
                        goodBean.setAllSelect(false);
                    }
                    allMoney = allMoney.setScale(2, BigDecimal.ROUND_DOWN);
                    goodBean.setAllCount(allCount);
                    goodBean.setAllMoney(allMoney);
                    goodBean.setCartItemIds(cartItemIds);
                    notifyDataSetChanged();
                    updateViewListener.update(goodBean.isAllSelect(), allCount, allMoney);
                    break;
                //单个子项item被点击
                case R.id.cb_item:
                    checkBox = (SmoothCheckBox) v;
                    int cCount = 0;//子item被选中的数量
                    int fcCount = 0;//父item被选中的数量
                    goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).setSelected(!checkBox.isChecked());
                    //遍历父item所有数据，统计被选中的item数量
                    for (int i = 0; i < goodBean.getCartItemList().get(groupId).getCartItemList().size(); i++) {
                        if (goodBean.getCartItemList().get(groupId).getCartItemList().get(i).isSelected()) {
                            cCount++;
                        }
                    }
                    //判断是否所有的子item都被选中，决定父item状态
                    if (cCount == goodBean.getCartItemList().get(groupId).getCartItemList().size()) {
                        goodBean.getCartItemList().get(groupId).setSelected(true);
                    } else {
                        goodBean.getCartItemList().get(groupId).setSelected(false);
                    }
                    //判断是否所有的父item都被选中，决定全选按钮状态
                    for (int i = 0; i < goodBean.getCartItemList().size(); i++) {
                        if (goodBean.getCartItemList().get(i).isSelected()) {
                            fcCount++;
                        }
                    }
                    if (fcCount == goodBean.getCartItemList().size()) {
                        goodBean.setAllSelect(true);
                    } else {
                        goodBean.setAllSelect(false);
                    }
                    //判断子item状态，更新结算总商品数和合计Money
                    if (!checkBox.isChecked()) {
                        allCount++;
//                        allMoney += Integer.valueOf(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity())
//                                * Double.parseDouble(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getUnitPrice());

                        allMoney = allMoney.add(new BigDecimal(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity()).multiply(new BigDecimal(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getUnitPrice())));
                        cartItemIds += goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getId() + ",";
                    } else {
                        allCount--;
//                        allMoney -= Integer.valueOf(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity())
//                                * Double.parseDouble(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getUnitPrice());
                        allMoney = allMoney.subtract(new BigDecimal(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity()).multiply(new BigDecimal(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getUnitPrice())));
                        cartItemIds = cartItemIds.replaceAll(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getId() + ",", "");
                    }
                    allMoney = allMoney.setScale(2, BigDecimal.ROUND_DOWN);
                    goodBean.setAllCount(allCount);
                    goodBean.setAllMoney(allMoney);
                    goodBean.setCartItemIds(cartItemIds);
                    notifyDataSetChanged();
                    updateViewListener.update(goodBean.isAllSelect(), allCount, allMoney);
                    break;
                case R.id.tv_reduce:
                    //减少商品数量
                    type = 0;
                    if (Integer.parseInt(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity()) > 1) {
                        changeNum();
                    }

                    break;
                case R.id.tv_add:
                    type = 1;
                    changeNum();
                    break;
                case R.id.item_layout:
                    /*跳转商品详情*/
                    if (goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getStatus().equals("3")) {
                        ToastUtil.showToast("该商品已下架");
                    } else {
                        Intent intent = new Intent();
                        intent.setClass(mContext, ProductDetailsActivity.class);
                        intent.putExtra("productId", goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getProductId());
                        mContext.startActivity(intent);
                    }
                    break;
                case R.id.group_item_layout:
                    /*跳转设计师的主页*/
                    Intent intent2 = new Intent();
                    intent2.setClass(mContext, DesignerHmePageActivity.class);
                    intent2.putExtra("dUserId", goodBean.getCartItemList().get(groupPosition).getUserId());
                    intent2.putExtra("type", "2");
                    mContext.startActivity(intent2);
                    break;
            }
        }
    };

    private void changeNum() {
        int num;
        String token = SharePreferencesHelper.getInstance(mContext).getString("token");
        MessageBean bean = new MessageBean();
        bean.setSkuId(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getSkuId());
        bean.setCartItemId(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getId());
        if (type == 0) {
            //减
            num = Integer.parseInt(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity()) - 1;
            bean.setType("2");
        } else {
            //加
            num = Integer.parseInt(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity()) + 1;
            bean.setType("1");
        }
        bean.setQuantity(num + "");
        bean.setToken(token);
        CommonInterface commonInterface = new CommonInterface(mContext, httpListener);
        commonInterface.getInterface("16033", JSON.toJSONString(bean));
    }

    HttpListener httpListener = new HttpListener() {
        @Override
        public void OnSuccess(String response) {
            super.OnSuccess(response);
            String errCode = JsonUtil.getFieldValue(response, "errCode");
            String errMsg = JsonUtil.getFieldValue(response, "errMsg");
            if (errCode.equals("0000")) {

                if (type == 0) {
                    //减
                    String goodCount = goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity();
                    if (Integer.valueOf(goodCount) > 1) {
                        goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).setQuantity(reduceCount(goodCount));
                        if (goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).isSelected()) {
//                            allMoney -= Double.parseDouble(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getUnitPrice());
                            allMoney = allMoney.subtract(new BigDecimal(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getUnitPrice()));
                            allMoney = allMoney.setScale(2, BigDecimal.ROUND_DOWN);
                            updateViewListener.update(goodBean.isAllSelect(), allCount, allMoney);
                        }

                    }
                } else {
                    //加
                    //添加商品数量
                    if (tag.contains(",")) {
                        split = tag.split(",");
                        groupId = Integer.parseInt(split[0]);
                        childId = Integer.parseInt(split[1]);
                    }
                    String goodCounts = goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getQuantity();
                    goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).setQuantity(addCount(goodCounts));
                    if (goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).isSelected()) {
//                        allMoney += Double.parseDouble(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getUnitPrice());
                        allMoney = allMoney.add(new BigDecimal(goodBean.getCartItemList().get(groupId).getCartItemList().get(childId).getUnitPrice()));
                        allMoney = allMoney.setScale(2, BigDecimal.ROUND_DOWN);
                        updateViewListener.update(goodBean.isAllSelect(), allCount, allMoney);
                    }
                }
                goodBean.setAllMoney(allMoney);
                notifyDataSetChanged();
            } else {
                ToastUtil.showToast("没有更多库存");
            }

        }

        @Override
        public void OnFail(String errorResponse) {
            super.OnFail(errorResponse);
            ToastUtil.showToast("没有更多库存");
        }
    };

    public void setChangedListener(UpdateView listener) {
        if (updateViewListener == null) {
            this.updateViewListener = listener;
        }
    }


    private String addCount(String var) {
        Integer integer = Integer.valueOf(var);
        integer++;
        return integer + "";
    }

    private String reduceCount(String var) {
        Integer integer = Integer.valueOf(var);
        if (integer > 1) {
            integer--;
        }
        return integer + "";
    }

    static class GroupViewHolder {
        SmoothCheckBox cbGroupItem;
        TextView tvPosition, clear_invalid;
        RelativeLayout group_item_layout;

        GroupViewHolder(View view) {
            cbGroupItem = (SmoothCheckBox) view.findViewById(R.id.cb_group_item);
            tvPosition = (TextView) view.findViewById(R.id.tv_position);
            group_item_layout = (RelativeLayout) view.findViewById(R.id.group_item_layout);
            clear_invalid = (TextView) view.findViewById(R.id.clear_invalid);
        }
    }

    static class ChildViewHolder {
        SmoothCheckBox cbItem;
        TextView tvPrice, tvGoodName, original_price;
        TextView etCount;
        TextView tvReduce;
        TextView tvAdd;
        ImageView imgIcon, img_product_state;
        TextView tv_good_choose;
        LinearLayout item_layout;
        LinearLayout ll_check;
        RelativeLayout layout_change_num;

        ChildViewHolder(View view) {
            cbItem = (SmoothCheckBox) view.findViewById(R.id.cb_item);
            tvPrice = (TextView) view.findViewById(R.id.tv_price);
            original_price = (TextView) view.findViewById(R.id.original_price);
            tvGoodName = (TextView) view.findViewById(R.id.tv_good_name);
            etCount = (TextView) view.findViewById(R.id.et_count);
            tvReduce = (TextView) view.findViewById(R.id.tv_reduce);
            tvAdd = (TextView) view.findViewById(R.id.tv_add);
            imgIcon = (ImageView) view.findViewById(R.id.img_icon);
            tv_good_choose = (TextView) view.findViewById(R.id.tv_good_choose);
            item_layout = (LinearLayout) view.findViewById(R.id.item_layout);
            ll_check = (LinearLayout) view.findViewById(R.id.ll_check);
            img_product_state = (ImageView) view.findViewById(R.id.img_product_state);
            layout_change_num = (RelativeLayout) view.findViewById(R.id.layout_change_num);
        }
    }

    private class clearOnClickListener implements View.OnClickListener {
        int position;

        public clearOnClickListener(int position) {
            this.position = position;
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.clear_invalid:

                    /**在这里写个接口，*/
                    onClickListenerCallBack.onClickClear(position);

                    break;

            }
        }
    }

    public interface OnClickListenerCallBack {
        void onClickClear(int position);

    }

    public OnClickListenerCallBack onClickListenerCallBack;

    public void setOnClickListenerCallBack(OnClickListenerCallBack onClickListenerCallBack) {
        this.onClickListenerCallBack = onClickListenerCallBack;
    }
}
